﻿using System;
using System.Collections.Generic;
using System.Windows.Media;
using StrategyGame.Scripts;

namespace StrategyGame.Model
{
    public class Person : Thing
    {
        private static int _nextId;
        public static int NextId { get { return _nextId++; } }

        public int DeathChance { get; set; }
        public int BirthChance { get; set; }
        public int RelationshipChance { get; set; }
        public int Id { get; private set; }

        public Person()
        {
            DeathChance = 0;
            RelationshipChance = 0;
            Relationships = new List<Relationship>();
            Id = NextId;
        }

        public string FamilyName { get; set; }
        public string FullName { get { return Name + " " + FamilyName; } }

        public List<Relationship> Relationships { get; set; }
        public bool IsDead { get; set; }
        public Person Father { get; set; }
        public Person Mother { get; set; }
        public Person Partner { get; set; }
        public int Age { get; set; }
        //public int BirthMonth { get; set; }
        //public int BirthDay { get; set; }
        //public Location Location { get; set; }
        public Color HairColour { get; set; }
        public Color EyeColor { get; set; }
        public uint Height { get; set; }
        public uint Weight { get; set; }
        //public uint BodyFat { get; set; }
        public bool IsMale { get; set; }
        //public List<Trait> Traits { get; set; }

        public Person GiveBirth(Person father, Random random)
        {
            if (IsMale) throw new Exception("Men can't give birth.");
            if (!father.IsMale) throw new Exception("Parents must be male and female.");
            if (IsDead || father.IsDead) throw new Exception("Parents must be alive.");
            if (Age < 16 || father.Age < 16) throw new Exception("Parents must be older than 16.");
            if (Age > 50 || father.Age > 70) return null;

            Person person = new Person();
            if (random.Next(100) < 45)
            {
                person.IsMale = true;
                person.Name = Names.Male[random.Next(0, Names.Male.Count)];
            } else
            {
                person.Name = Names.Female[random.Next(0, Names.Female.Count)];
            }
            person.Father = father;
            person.Mother = this;
            person.FamilyName = father.FamilyName;
            return person;
        }

        public new string ToString()
        {
            return Name + " " + FamilyName + " ["+Id+"] "+(IsMale?"Male":"Female") +":"+ Age + (IsDead ? ":Dead" : "") + (Partner != null ? ":Married" : "");
        }
    }
}
